# -*- coding: utf-8 -*-
from buss_api.config_tools import ConfigTools
from global_data.constant_data import ConstantData
from utils.file_utils import FileUtils


class GlobalData(object):
    WORK_PATH = ""
    WORK_PATH_COMMON = ""
    SYS_NAME = ""
    SYS_ICON = "ri.xbox-fill"  # 系统图标
    SYS_IMG = "fa5b.skyatlas"  # 系统图片
    TRAY_ICON = "ri.xbox-fill"  # 托盘图标
    SYS_SHOW = [1, 1, 1, 0, 0, 1]

    LOG_BASE_PATH = "./log"
    LOG_LEVEL = "info"

    ZMQ_XPUB_IP = "127.0.0.1"
    ZMQ_XPUB_PORT = "10080"
    ZMQ_XSUB_IP = "127.0.0.1"
    ZMQ_XSUB_PORT = "10081"

    DB_SOURCE_HOST = "127.0.0.1"
    DB_SOURCE_PORT = 3306
    DB_SOURCE_USER = "root"
    DB_SOURCE_PWD = "#chengan2021#"
    DB_SOURCE_DB = "tracesource"
    DB_TARGET_HOST = "127.0.0.1"
    DB_TARGET_PORT = 3306
    DB_TARGET_USER = "root"
    DB_TARGET_PWD = "#chengan2021#"
    DB_TARGET_DB = "tracesource"


    SERVICE_GATEWAY_SYSCONFIG = "sysConfig.txt"
    SERVICE_GATEWAY_SENDCONFIG = "sendConfig.txt"
    SERVICE_PROGRAM_PATH = "c:/datalink"
    SERVICE_FILE_PATH = "c:/datalink/update"
    SERVICE_BACKUP_PATH = "c:/datalink/backup"
    SERVICE_GATEWAY_NAME = "monSmartGateway"
    SERVICE_WEB_NAME = "monitormanageweb"
    SERVICE_GATEWAY_PROCE_NAME = "monSmartGateway"
    SERVICE_WEB_PROCE_NAME = "mon"

    CHART_CSV_PATH = "c:/home/icloudp/csv"
    CHART_CSV_TYPE = "1"
    CHART_Y_IS_FIXED = "0"
    CHART_Y_MINVAL = "-20"
    CHART_Y_MAXVAL = "30"

    SERVICE_STATUS = {
        1: "STOPPED",
        2: "START_PENDING",
        3: "STOP_PENDING",
        4: "RUNNING",
        5: "CONTINUE_PENDING",
        6: "PAUSE_PENDING",
        7: "PAUSED"
    }

    @classmethod
    def init_config(cls):
        # 系统相关
        GlobalData.SYS_NAME = ConfigTools.get_value("system", "systemName", "网关智能工具")
        GlobalData.SYS_SHOW = ConfigTools.get_value("system", "showStatus", "quit").split(",")

        # 加载日志相关配置
        GlobalData.WORK_PATH = ConstantData.WORK_PATH
        GlobalData.WORK_PATH_COMMON = ConstantData.WORK_PATH_COMMON
        GlobalData.LOG_BASE_PATH = ConfigTools.get_value("log", "basePath", "./log")
        FileUtils.mkdir(GlobalData.LOG_BASE_PATH)
        GlobalData.LOG_LEVEL = ConfigTools.get_value("log", "level", "info")

        # 加载zmq相关配置
        GlobalData.ZMQ_XPUB_IP = ConfigTools.get_value("zmq", "xpubIp", "127.0.0.1")
        GlobalData.ZMQ_XPUB_PORT = ConfigTools.get_value("zmq", "xpubPort", "127.0.0.1")
        GlobalData.ZMQ_XSUB_IP = ConfigTools.get_value("zmq", "xsubIp", "127.0.0.1")
        GlobalData.ZMQ_XSUB_PORT = ConfigTools.get_value("zmq", "xsubPort", "127.0.0.1")

        # 加载db相关配置
        GlobalData.DB_SOURCE_HOST = ConfigTools.get_value("db", "sourceIp", "127.0.0.1")
        GlobalData.DB_SOURCE_PORT = ConfigTools.get_value("db", "sourcePort", "3306")
        GlobalData.DB_SOURCE_USER = ConfigTools.get_value("db", "sourceUser", "root")
        GlobalData.DB_SOURCE_PWD = ConfigTools.get_value("db", "sourcePwd", "")
        GlobalData.DB_SOURCE_DB = ConfigTools.get_value("db", "sourceDb", "tracesource")
        GlobalData.DB_TARGET_HOST = ConfigTools.get_value("db", "targetIp", "127.0.0.1")
        GlobalData.DB_TARGET_PORT = ConfigTools.get_value("db", "targetPort", "3306")
        GlobalData.DB_TARGET_USER = ConfigTools.get_value("db", "targetUser", "root")
        GlobalData.DB_TARGET_PWD = ConfigTools.get_value("db", "targetPwd", "")
        GlobalData.DB_TARGET_DB = ConfigTools.get_value("db", "targetDb", "tracesource")

        # 加载服务相关
        GlobalData.SERVICE_PROGRAM_PATH = ConfigTools.get_value("service", "programPath", GlobalData.SERVICE_PROGRAM_PATH)
        GlobalData.SERVICE_FILE_PATH = ConfigTools.get_value("service", "filePath", GlobalData.SERVICE_FILE_PATH)
        GlobalData.SERVICE_BACKUP_PATH = ConfigTools.get_value("service", "backupPath", GlobalData.SERVICE_BACKUP_PATH)

        # 加载图表相关
        GlobalData.CHART_CSV_PATH = ConfigTools.get_value("chart", "csvpath", GlobalData.CHART_CSV_PATH)
        GlobalData.CHART_CSV_TYPE = ConfigTools.get_value("chart", "csvtype", GlobalData.CHART_CSV_TYPE)
        GlobalData.CHART_Y_IS_FIXED = ConfigTools.get_value("chart", "yIsFixed", GlobalData.CHART_Y_IS_FIXED)
        GlobalData.CHART_Y_MINVAL = ConfigTools.get_value("chart", "yMinVal", GlobalData.CHART_Y_MINVAL)
        GlobalData.CHART_Y_MAXVAL = ConfigTools.get_value("chart", "yMaxVal", GlobalData.CHART_Y_MAXVAL)


if __name__ == '__main__':
    print("Python")
